<!DOCTYPE html>
<html lang="en">

<head>
    <head/>
    <title>预约挂号</title>
    <titleType style="display: none;">yygh</titleType>
    <link rel="stylesheet" href="/static/css/qyjm/page.css" />
    <link rel="stylesheet" href="/static/css/appointment/appointment.css" />
    <%- include('./_global/appendJs') %>

</head>
<style>
    body {
        background: #fbfafa;
    }

    .filtrate-box li {
        border-bottom: 1px solid #DDDDDD;
    }

    .yygh-box .filtrate-sub-check {
        top: 3.625rem;
    }

    .search input {
        width: 94%;
        height: 2.4rem;
        border-radius: 5px;
        border: none;
        background: #f1f1f1;
        margin: .5rem 3%;
        font-size: 1.2rem;
        text-indent: .2rem;
        text-align: center;
    }

    .search input:focus {
        outline: none;
    }
    .yygh-box .doctor-list-box>ul>li .text-box span.yellow-text {
        border: 1px solid #f89e00;
        border-radius: 18px;
        padding: 0px 5px 0px 5px;
        margin-left: 0px;
    }
</style>

<body>
    <!-- <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);">
                    <i class="iconfont icon-back"></i>
                </a>
            </div>
            <div class="title">预约挂号</div>
        </div>
    </header> -->
    <section class="page-wrap yygh-box">
        <!-- <div class="search">
            <form action="javascript:;" >
                <input placeholder="搜索医院" type="search" id="queryInput" >
            </form>

        </div> -->
        <div class="wdqy-box">
            <ul class="clearfix administrative-area">
                <li id="hosLevelListBox" class="wdqy-list-box" ref-target="xzqhBox" data-linkage-target="yyxxListBox">
                    <span>医院级别</span>
                    <i class="wdqy-arrow"></i>
                </li>
                <li id="hosTypeListBox" class="wdqy-list-box" ref-target="xzqhBox" data-linkage-target="yyxxListBox">
                    <span>医院类型</span>
                    <i class="wdqy-arrow"></i>
                </li>
            </ul>
        </div>
        <div class="bg"></div>
        <div class="down-list">
            <div class="wdqy-select-box" id="hosLevelBox" ref-target="xzqhListBox" idx="0">
                <ul>
                    <li class="actived">
                        <span>全部</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="0">社区卫生服务中心</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="1">一级</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="2">二级</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="3">三级</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="9">未评级</span>
                    </li>
                </ul>
            </div>
            <div class="wdqy-select-box" id="hosTypeBox" ref-target="xzqhListBox" idx="1">
                <ul>
                    <li class="actived">
                        <span>不限</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="1">综合性医院</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="2">专科医院</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="3">中医医院</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="4">专科疾病防治所(站，中心)</span>
                    </li>
                    <li class="">
                        <span data-xzqhdm="5">妇幼保健院(所，站)</span>
                    </li>
                </ul>
            </div>
        </div>

        <div class="doctor-list-box" id="hosDiv" style="margin-top:0;">
            <ul id="hosUl">
            </ul>
        </div>
    </section>
</body>
<script src="/static/lib/forweb.js"></script>
<script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
<script src="/static/js/<%=type%>/pageUrl.js"></script>
<script src="/static/js/<%=type%>/yygh.js"></script>
<script type="text/html" id="hosLi">
    <li>
        <a href="javascript:void(0);">
            <i class="hospital-icon hosImgUrl" style="height: 3.806rem;margin-top: 1rem;width: 5.075rem;"></i>
            <div class="text-box">
                <p>
                    <span class="title-text hosName" style="width:12.0rem"></span>
                    

                </p>
                <p>
                    <span class="yellow-text hosLevel"></span>
                    <span class="yellow-text isMedicare"></span>
                </p>
                <p>
                    <span class="doctorCount"></span>

                </p>
                <p>
                    <span class="telPhone"></span>

                </p>
            </div>
            <div class="item-after">
                <i class="iconfont icon-more"></i>
            </div>
        </a>
    </li>
</script>

<script type="text/javascript">

    function toKslb(hos) {
        var hosInfo = JSON.parse(hos.replace(/\s/g, ""));
        var requestFrom = $.QuickUrlUtils.getRequest("from");
        if (requestFrom == "treatment") {
            StoreCache.setCache("YYGH_HOSINFO", hosInfo)
            $.QuickUrlUtils.reBackAndRefreshJSBridge("*");
        } else {
            $.pageSwitch.goToUrl("myOrder", "hosDetail", "hosCode=" + hosInfo["hosCode"]);
        }
    }


    var page_yygh = (function ($, page_yygh) {
        var status_hosType = {
            "1" : "综合性医院",
            "2" : "专科医院",
            "3" : "中医医院",
            "4" : "专科疾病防治所(站，中心)",
            "5" : "妇幼保健院(所，站)"
        };
        var uid = $.QuickUrlUtils.getRequest("uid");
        // uid = "8a81dc446362aac70163680a6c3f007a";
        StoreCache.setCache("uid", uid);


        /**加载视图*/
        function initView() {
            $.ajax({
                type: "GET", // 使用get方法访问后台
                dataType: "json", // 返回json格式的数据
                "headers": {
                    "Content-Type": "application/json",
                    "Cache-Control": "no-cache",
                },
                url: "/api1/changping-user/api/customer/findCustomerByUid?uid=" + uid, // 要访问的后台地址
                success: function (data) {
                    if (data.code == "0") {
                        if (data && data.data) {
                            StoreCache.setCache("yyghUserInfo", data.data);
                        }
                    } else {
                        $.QuickAlert.alertFail({
                            content: data.msg
                        });
                    }
                }
            });

            $(".wdqy-box li").on("click", function () {
                if ($(this).hasClass("active")) {
                    $(this).removeClass("active");
                    $(".down-list>div").eq($(this).index()).removeClass("selected");
                    $(".bg").removeClass("selected");
                    $('body').css({
                        overflow: "visible",
                        height: "100%"
                    }); // 删除style中相应的属性

                } else {
                    //判断，当前的li添加active类，其他的删除active类
                    $(this).addClass("active").siblings("li").removeClass("active");
                    //对应索引值的div添加selected类，其他的删除selected类
                    $(".down-list>div").eq($(this).index()).addClass("selected").siblings("div").removeClass(
                        "selected");
                    $(".bg").addClass("selected");
                    $('body').css({
                        overflow: 'hidden',
                        height: $(window).height() + 'px'
                    });
                }
            });

            // 点击bg让当前的ul隐藏
            $(".bg").on("click", function () {
                $(".wdqy-box li").each(function () {
                    if ($(this).hasClass("active")) {
                        $(this).removeClass("active");
                        $(".down-list>div").eq($(this).index()).removeClass("selected");
                        $(".bg").removeClass("selected");
                        $('body').css({
                            overflow: "visible",
                            height: "100%"
                        }); // 删除style中相应的属性
                    }
                })

            });










            $("#hosLevelBox ").on("click", "li", function () {
                $("#hosTypeBox li:eq(0)").addClass("actived").siblings("li").removeClass("actived");
                $(".wdqy-box li").eq(1).find("span").text("医院类型");                                
                var i = $(this).index();
                var hosInfoList = $("body").data("hosInfo");
                if (!hosInfoList) {
                    return false;    
                }
                if (!($(this).hasClass("actived"))) {
                    $(this).addClass("actived").siblings("li").removeClass("actived");

                    var xzqhdm = $(this).find("span").data("xzqhdm");
                    if (i != 0) {

                        var WanSalary2 = hosInfoList.filter(function(item){
                            return item.hosGrade == xzqhdm;
                        })
                        page_yygh.hospitalListHandler(WanSalary2);
                    } else {
                        page_yygh.hospitalListHandler(hosInfoList);
                    }
                    
                }
                var text = $(this).find("span").text();
                var xzqhdm = $(this).find("span").data("xzqhdm") ? $(this).find("span").data("xzqhdm") :
                    "";
                var index = $(this).parent().parent().attr("idx");
                $(".wdqy-box li").eq(index).removeClass("active");
                $(".wdqy-box li").eq(index).find("span").text(text);
                $(".wdqy-box li").eq(index).find("span").data("xzqhdm", xzqhdm);
                $(".bg").removeClass("selected");
                $(this).parent().parent().removeClass("selected");
                $('body').css({
                    overflow: "visible",
                    height: "100%"
                }); // 删除style中相应的属性 

            });

            $("#hosTypeBox ").on("click", "li", function () {
                $("#hosLevelBox li:eq(0)").addClass("actived").siblings("li").removeClass("actived");
                $(".wdqy-box li").eq(0).find("span").text("医院级别");                
                var i = $(this).index();
                var hosInfoList = $("body").data("hosInfo");
                if (!hosInfoList) {
                    return false;    
                }
                if (!($(this).hasClass("actived"))) {
                    $(this).addClass("actived").siblings("li").removeClass("actived");

                    var xzqhdm = $(this).find("span").data("xzqhdm");
                    if (i != 0) {

                        var WanSalary2 = hosInfoList.filter(function(item){
                            return item.hospitalType == xzqhdm;
                        })
                        page_yygh.hospitalListHandler(WanSalary2);
                    } else {
                        page_yygh.hospitalListHandler(hosInfoList);
                    }
                    
                }
                var text = $(this).find("span").text();
                var xzqhdm = $(this).find("span").data("xzqhdm") ? $(this).find("span").data("xzqhdm") :
                    "";
                var index = $(this).parent().parent().attr("idx");
                $(".wdqy-box li").eq(index).removeClass("active");
                $(".wdqy-box li").eq(index).find("span").text(text);
                $(".wdqy-box li").eq(index).find("span").data("xzqhdm", xzqhdm);
                $(".bg").removeClass("selected");
                $(this).parent().parent().removeClass("selected");
                $('body').css({
                    overflow: "visible",
                    height: "100%"
                }); // 删除style中相应的属性 

            });






        }

        /**加载数据*/
        function initData() {
            /**加载医院信息*/
            var params = {};
            page_yygh.initHosInfo(params);
        }


        /**加载医院信息*/
        function initHosInfo(params) {
            /**获取用户经纬度有延迟，需要回调获取*/
            if (params["sortType"] == "1") {
                params["mapType"] = "AMap";
                $.JkcsUtils.nativePermission({
                    "type": "location",
                    "callBackMethod": "callBack",
                    "params": params
                });
                //			params["userLocation"] = $.JkcsUtils.getUserLocation("callBack",params);
            } else {
                page_yygh.callBack(params);
            }
        }

        function callBack(params) {
            //params["userLocation"] = params["longitude"]+","+params["latitude"];
            params = {
                "districtCode": "",
                "hoscode": "",
                "hosname": "",
                // "pageNum": 1,
                // "pageSize": 10
            }
            $("#hosUl").remove();
            var hosUl = $("<ul>").attr({
                "id": "hosUl"
            });
            $("#hosDiv").append(hosUl);
            $.ajax({
                type: "POST", // 使用get方法访问后台
                dataType: "json", // 返回json格式的数据
                "headers": {
                    "Content-Type": "application/json",
                    "Cache-Control": "no-cache",
                },
                url: "/api/yyghAdapter/getHospital.service", // 要访问的后台地址
                data: JSON.stringify(params), // 要发送的数据
                success: function (data) {
                    if (data.code == "SUCCESS") {
                        $("body").data("hosInfo", data["data"]["hospitals"]);
                        page_yygh.hospitalListHandler(data["data"]["hospitals"]);
                    } else {
                        $.QuickAlert.alertFail({
                            content: data.message
                        });
                    }
                }
            });
        }

        function hospitalListHandler(result) {
            $("#hosUl").empty();
            var type = "";
            $("#orderChildren").find("li").each(function () {
                if ($(this).hasClass("active")) {
                    type = $(this).attr("value");
                    return;
                }
            });
            // result = result.data;
            // var pages = result["pageCount"];
            // var ary = result["hospitals"];
            var lis = [];
            if (result && result.length > 0) {

                $(result).each(function (index, item) {
                    var value = item["distance"];
                    if (value == "" || value == null) {
                        value = "0";
                    }
                    var hosLi = $($("#hosLi").html());
                    if (type != "1") {
                        $(hosLi).find(".distance").remove();
                    }
                    //$(hosLi).find(".hosImgUrl").css("background","url(\"/static/images/hospital1.png\") no-repeat");
                    $(hosLi).find(".hosName").text(item["hosName"]);
                    $(hosLi).find(".hosLevel").text(page_yygh.getHosGrade(item["hosGrade"]) + page_yygh.getHosLevel(
                        item["hosLevel"])); //hosLevel
                    $(hosLi).find(".isMedicare").text(status_hosType[item["hospitalType"]]);
                    $(hosLi).find(".doctorCount").text("地址：" + item["hosAddress"]);
                    $(hosLi).find(".telPhone").text("电话：" + item["lxdh"] ? item["lxdh"] : "");
                    var hosInfo = item;
                    hosInfo.hosDesc = "";
                    $(hosLi).find("a").attr("onclick", "toKslb('" + JSON.stringify(hosInfo) + "')");
                    lis.push($(hosLi).prop("outerHTML"));
                });
                // obj.next(lis.join(''), obj.page < pages);
                $("#hosUl").html(lis.join(''));
            } else {
                $("#hosUl").html("<div style='width:100%;text-align:center; font-weight:bold;color:#000;padding-top:20px'>暂无信息</div>");
            }
        }

        /**获取医院等级*/
        function getHosLevel(hosLevel) {
            var value = "";
            if (hosLevel == "0") {
                value = "特等";
            } else if (hosLevel == "1") {
                value = "甲等";
            } else if (hosLevel == "2") {
                value = "乙等";
            } else if (hosLevel == "3") {
                value = "丙等";
            } else {
                value = "合格";
            }
            return value;
        }

        /**判断是否是医保*/
        function getIsMedicare(medicare) {
            var value = "";
            if (medicare == "0") {
                value = "医保";
            } else //if(medicare == "1")
            {
                value = "非医保";
            }
            return value;
        }

        /**获取医院级别*/
        function getHosGrade(hosGrade) {
            var value = "";
            if (hosGrade == "0") {
                value = "社区卫生服务中心";
            } else if (hosGrade == "1") {
                value = "一级";
            } else if (hosGrade == "2") {
                value = "二级";
            } else if (hosGrade == "3") {
                value = "三级";
            } else if (hosGrade == "9") {
                value = "未评级";
            }
            return value;
        }

        function queryByCondition(obj) {

            $("#queryInput").blur();
            var params = {
                hosname: $("#queryInput").val(),
                pageNum: '1',
                pageSize: '10'
            }
            var api = '';
            page_yygh.initHosInfo(params, api);
        }

        var cfg_def = {
            initView: initView,
            initData: initData,
            initHosInfo: initHosInfo,
            callBack: callBack,
            hospitalListHandler: hospitalListHandler,
            getHosLevel: getHosLevel,
            getIsMedicare: getIsMedicare,
            getHosGrade: getHosGrade,
            queryByCondition: queryByCondition,

        }

        page_yygh.init = function (cfg) {
            $.extend(page_yygh, cfg_def, cfg);
            page_yygh.initData();
            page_yygh.initView();

            $("#queryInput").on("click", function() {
                $.pageSwitch.goToUrl("myOrder", "appointmentSearch");


            });



        }


        // input框获取焦点跳转到下一页
		

        return page_yygh;
    })(jQuery, {});
</script>


</html>